<?php
define("DEPLOYED",false);
require "global.php";
require "taobao.php";

include_once FANWE_ROOT.'sdks/taobao/TopClient.php';
include_once FANWE_ROOT.'sdks/taobao/request/ItemsSearchRequest.php';
include_once FANWE_ROOT.'sdks/taobao/request/TaobaokeItemsConvertRequest.php';

$c = new TopClient;
$c->appkey = APPKEY;
$c->secretKey = SECRET;

$pro_db = new PormotionDB();

$mailList = array("2308349525@qq.com",'745158412@qq.com');
$title = iconv('utf-8','gbk','双11来了，淘宝天猫优选商品半价大优惠！');

$list = $pro_db->getSendPromotionList();
foreach($list as $row){
	$goods_url = $row['goods_url'];
	$gid = getID($goods_url);
	$item_req = new TaobaokeItemsDetailGetRequest;
	$item_req->setFields("click_url");
	$item_req->setPid(10135627);
	$item_req->setNumIids($gid);
	$item_resp = (array)$c->execute($item_req);
	print_r($item_resp);
	sleep(1);
	if($item_resp){
		//print_r($item_resp);
		$taoke_item_details = (array)$item_resp['taobaoke_item_details'];
		$taobaoke_item_detail = (array)$taoke_item_details['taobaoke_item_detail'];
		if($taobaoke_item_detail){
			$click_url = $taobaoke_item_detail['click_url'];
			echo 'click_url:'.$click_url.PHP_EOL;
			$baidu_url = encodeBaiduShortUrl($click_url);
			echo 'baidu:'.$baidu_url.PHP_EOL;
			$weibo_url = encodeSinaShortUrl($click_url);
			echo 'weibo:'.$weibo_url.PHP_EOL;
			$pro_db->updatePromotionData($row['id'], $baidu_url,$weibo_url);
		}
	}
}
?>